/*
 * Object.cpp
 *
 *  Created on: Nov 27, 2008
 *      Author: Ry
 */
#include <GL/glew.h>
#include <iostream>
#include "world/Object.h"

using namespace std;

Object::Object() {
	this->prototype = NULL;
	this->motionController = NULL;
	transform = btTransform::getIdentity();
	scale = btVector3(1, 1, 1);
}

Object::Object(Prototype *prototype) {
	this->prototype = prototype;
	this->motionController = NULL;
	transform = btTransform::getIdentity();
	scale = btVector3(1, 1, 1);
};

void Object::positionAt(float x, float y, float z) {
	this->transform.setOrigin(btVector3(x, y, z));
}

void Object::positionAt(const Vector3 &v) {
	this->transform.setOrigin(btVector3(v.x, v.y, v.z));
}

void Object::setRotation(float pitch, float yaw, float roll) {
	this->transform.setRotation(btQuaternion(btRadians(yaw), btRadians(pitch), btRadians(roll)));
}

void Object::setScale(float scale) {
	this->scale = btVector3(scale, scale, scale);
}

void Object::draw() {
	btScalar mat[16];
	transform.getOpenGLMatrix(mat);
	glMultMatrixf(mat);
	glScalef(scale.x(), scale.y(), scale.z());

	if (prototype != NULL) {
		prototype->draw();
	}

	for (unsigned int i = 0; i < children.size(); i++) {
		children[i]->draw();
	}
}

Object::~Object() {

}
